<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/3/28
 * Time: 14:21
 */

namespace app\admin\controller;


use app\admin\model\LabelsModel;
use think\Request;
use think\Config;

class Labels extends Base
{
    protected $labelsModel;

    /*
     * 依赖注入Model
     * */
    public function __construct(LabelsModel $labelsModel){
        parent::__construct();
        $this->labelsModel = $labelsModel;
    }

    /*
     * 角色列表
     * */
    public function labels_index(){
        $this->assign("data",$this->labelsModel->listAll());
        return $this->fetch('labels/index');
    }

    /*
    * 新增角色
    * */
    public function labels_add(){
        if(Request::instance()->isPost()){
            $validate=$this->labelsModel->validate_model('add');
            if ($validate['code']){
                return $this->labelsModel->add();
            }else{
                return $validate;
            }
        }
        $category=Config::get('labels_category');
        $this->assign("category",$category);
        return $this->fetch('labels/add');
    }

    /*
    * 修改角色
    * */
    public function labels_edit(){
        if(Request::instance()->isPost()){
            $validate=$this->labelsModel->validate_model('edit');
            if ($validate['code']){
                return $this->labelsModel->edit();
            }else{
                return $validate;
            }
        }
        $id=input('get.id/d');
        $category=Config::get('labels_category');
        $this->assign("category",$category);
        $this->assign("data",$this->labelsModel->getById($id));
        return $this->fetch('labels/edit');
    }

    /*
    * 删除角色
    * */
    public function labels_del(){
        return $this->labelsModel->del();
    }


}